#include "batchenhancepanel.h"
#include <QLabel>

BatchEnhancePanel::BatchEnhancePanel(QWidget* parent) : QWidget(parent)
{
    setupUI();
    createConnections();
}

void BatchEnhancePanel::setupUI()
{
    QFormLayout* layout = new QFormLayout(this);
    
    // 亮度滑块
    m_brightnessSlider = new QSlider(Qt::Horizontal);
    m_brightnessSlider->setRange(-100, 100);
    m_brightnessSlider->setValue(0);
    layout->addRow(tr("亮度:"), m_brightnessSlider);
    
    // 对比度滑块
    m_contrastSlider = new QSlider(Qt::Horizontal);
    m_contrastSlider->setRange(-100, 100);
    m_contrastSlider->setValue(0);
    layout->addRow(tr("对比度:"), m_contrastSlider);
    
    // 锐化滑块
    m_sharpnessSlider = new QSlider(Qt::Horizontal);
    m_sharpnessSlider->setRange(0, 100);
    m_sharpnessSlider->setValue(0);
    layout->addRow(tr("锐化:"), m_sharpnessSlider);
    
    // 降噪复选框
    m_denoiseCheck = new QCheckBox(tr("降噪"));
    layout->addRow("", m_denoiseCheck);
    
    // 自动纠偏复选框
    m_autoRotateCheck = new QCheckBox(tr("自动校正"));
    layout->addRow("", m_autoRotateCheck);
    
    // 颜色模式下拉框
    m_colorModeCombo = new QComboBox;
    m_colorModeCombo->addItems({tr("原色"), tr("灰度"), tr("黑白"), tr("深褐色"), tr("反色")});
    layout->addRow(tr("颜色模式:"), m_colorModeCombo);
    
    // 预设方案下拉框
    m_presetCombo = new QComboBox;
    m_presetCombo->addItems({tr("自定义"), tr("文本阅读"), tr("漫画模式"), tr("高对比度")});
    layout->addRow(tr("预设方案:"), m_presetCombo);
}

void BatchEnhancePanel::createConnections()
{
    connect(m_presetCombo, &QComboBox::currentTextChanged,
            this, &BatchEnhancePanel::applyPreset);
}

EnhanceParams BatchEnhancePanel::getParameters() const
{
    EnhanceParams params;
    params.brightness = m_brightnessSlider->value();
    params.contrast = m_contrastSlider->value();
    params.sharpness = m_sharpnessSlider->value();
    params.denoise = m_denoiseCheck->isChecked();
    params.autoRotate = m_autoRotateCheck->isChecked();
    params.colorMode = m_colorModeCombo->currentIndex();
    return params;
}

void BatchEnhancePanel::resetParameters()
{
    m_brightnessSlider->setValue(0);
    m_contrastSlider->setValue(0);
    m_sharpnessSlider->setValue(0);
    m_denoiseCheck->setChecked(false);
    m_autoRotateCheck->setChecked(false);
    m_colorModeCombo->setCurrentIndex(0);
    m_presetCombo->setCurrentIndex(0);
}

void BatchEnhancePanel::setParameters(const EnhanceParams& params)
{
    m_brightnessSlider->setValue(params.brightness);
    m_contrastSlider->setValue(params.contrast);
    m_sharpnessSlider->setValue(params.sharpness);
    m_denoiseCheck->setChecked(params.denoise);
    m_autoRotateCheck->setChecked(params.autoRotate);
    m_colorModeCombo->setCurrentIndex(params.colorMode);
}

void BatchEnhancePanel::applyPreset(const QString& presetName)
{
    if (presetName == tr("文本阅读")) {
        m_brightnessSlider->setValue(10);
        m_contrastSlider->setValue(20);
        m_sharpnessSlider->setValue(30);
        m_presetCombo->setCurrentIndex(1);
    }
    else if (presetName == tr("漫画模式")) {
        m_brightnessSlider->setValue(0);
        m_contrastSlider->setValue(30);
        m_sharpnessSlider->setValue(20);
        m_presetCombo->setCurrentIndex(2);
    }
    else if (presetName == tr("高对比度")) {
        m_brightnessSlider->setValue(10);
        m_contrastSlider->setValue(50);
        m_sharpnessSlider->setValue(40);
        m_presetCombo->setCurrentIndex(3);
    }
}

void BatchEnhancePanel::retranslateUi()
{
    // 重新设置所有文本
    QFormLayout* layout = qobject_cast<QFormLayout*>(this->layout());
    if (layout) {
        qobject_cast<QLabel*>(layout->labelForField(m_brightnessSlider))->setText(tr("亮度:"));
        qobject_cast<QLabel*>(layout->labelForField(m_contrastSlider))->setText(tr("对比度:"));
        qobject_cast<QLabel*>(layout->labelForField(m_sharpnessSlider))->setText(tr("锐化:"));
        qobject_cast<QLabel*>(layout->labelForField(m_presetCombo))->setText(tr("预设方案:"));
    }
    
    m_presetCombo->clear();
    m_presetCombo->addItems({tr("自定义"), tr("文本阅读"), tr("漫画模式"), tr("高对比度")});
} 